package org.fuys.coder.domain.auth.service.handler.register.impl;

import org.fuys.coder.common.exception.BusinessException;
import org.fuys.coder.infrastructure.model.dto.UserDTO;
import org.fuys.coder.domain.auth.service.handler.register.RegisterHandler;
import org.fuys.coder.domain.favorites.service.IFavoriteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.domain.auth.service.handler.register.impl
 * @className: FavoriteInitHandler
 * @author: WangJing
 * @description: 收藏夹初始化处理器
 * @date: 2024/6/19 18:58
 * @version: 1.0
 */
@Service
public class FavoriteInitHandler implements RegisterHandler {

    @Resource
    private IFavoriteService favoriteService;

    @Override
    public boolean handle(UserDTO userDTO) throws BusinessException {
        try {
            final long newEmptyFavorite = favoriteService.createNewEmptyFavorite();
            favoriteService.saveRecord(userDTO.getId(), newEmptyFavorite);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("初始化收藏夹相关业务失败!");
        }
    }
}
